<?php
namespace App\Services\Impl;

use App\Services\IManagerService;
use App\User;

/**
 * Created by PhpStorm.
 * User: ownfi
 * Date: 2017-04-11
 * Time: 10:56
 */
class ManagerServiceImpl implements IManagerService
{
    public function getManagerList(array $wheres = [])
    {
        $model = User::orderBy('created_at','DESC');
        if ($wheres){
            $model->where($wheres);
        }
        return $model->paginate(config('common.perpage'));
    }

    public function add($name, $email, $password)
    {
        return User::create([
            'name' => $name,
            'email' => $email,
            'password' => bcrypt($password),
        ]);
    }

    public function edit($manager_id,$name, $email)
    {
        return User::where('id',$manager_id)->take(1)->update([
            'name'=>$name,
            'email'=>$email
        ]);
    }

    public function modifyPassword($manager_id,$new_password)
    {
        return User::where('id',$manager_id)->take(1)->update([
            'password' => bcrypt($new_password),
        ]);
    }

    public function delete($manager_id)
    {
        return User::destroy($manager_id);
    }

}